/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package projetointegrado;

import java.awt.Rectangle;
import java.awt.event.KeyEvent;

/**
 *
 * @author Emerson
 */
public class MovementMulti {

    final int WIDTH;
    final int HEIGHT;
    private KeyboardInput keyboard;
    private Rectangle jogador;
    private PlayerMulti pm;

    public MovementMulti(PlayerMulti pm, KeyboardInput keyboard, int WIDTH, int HEIGHT) {
        this.pm = pm;
        this.keyboard = keyboard;
        this.WIDTH = WIDTH;
        this.HEIGHT = HEIGHT;
        PainelMultiplayer.p.setPosChar("src/Imagens/char_tibia_down1.png");
    }

    public void Movimenta(Rectangle jogador) {
        this.jogador = jogador;

        if (keyboard.keyDown(KeyEvent.VK_DOWN)) {


            //Flag.colisao = false;
            PainelMultiplayer.p.xa = PainelMultiplayer.p.x;
            PainelMultiplayer.p.ya = PainelMultiplayer.p.y;
            //PainelMultiplayer.p.setPosChar("src/Imagens/char_tibia_down2.png");
            PainelMultiplayer.p.setPosY(PainelMultiplayer.p.y += PainelMultiplayer.p.dy);

            if (PainelMultiplayer.p.y + PainelMultiplayer.p.h > HEIGHT - 1) {
                PainelMultiplayer.p.setPosY(PainelMultiplayer.p.y = HEIGHT - PainelMultiplayer.p.h - 1);
            }

            //player.setPosChar("src/Imagens/char_tibia_down2.png");
            ProjetoIntegrado.pmulti.enviaObjeto();
            //System.out.println("DOWN");



        } else if (keyboard.keyDown(KeyEvent.VK_UP)) {
            PainelMultiplayer.p.xa = PainelMultiplayer.p.x;
            PainelMultiplayer.p.ya = PainelMultiplayer.p.y;
            //PainelMultiplayer.p.setPosChar("src/Imagens/char_tibia_up2.png");
            PainelMultiplayer.p.setPosY(PainelMultiplayer.p.y -= PainelMultiplayer.p.dy);
            if (PainelMultiplayer.p.y < 0) {
                PainelMultiplayer.p.y = 0;
            }
            ProjetoIntegrado.pmulti.enviaObjeto();
        } else if (keyboard.keyDown(KeyEvent.VK_LEFT)) {
            PainelMultiplayer.p.xa = PainelMultiplayer.p.x;
            PainelMultiplayer.p.ya = PainelMultiplayer.p.y;
            //PainelMultiplayer.p.setPosChar("src/Imagens/char_tibia_left2.png");
            PainelMultiplayer.p.setPosX(PainelMultiplayer.p.x -= PainelMultiplayer.p.dx);
            if (PainelMultiplayer.p.x < 0) {
                PainelMultiplayer.p.x = 0;
            }
            ProjetoIntegrado.pmulti.enviaObjeto();
        }else if (keyboard.keyDown(KeyEvent.VK_RIGHT)) {
            PainelMultiplayer.p.xa = PainelMultiplayer.p.x;
            PainelMultiplayer.p.ya = PainelMultiplayer.p.y;
            //PainelMultiplayer.p.setPosChar("src/Imagens/char_tibia_right2.png");
            PainelMultiplayer.p.setPosX(PainelMultiplayer.p.x += PainelMultiplayer.p.dx);
            if (PainelMultiplayer.p.x + PainelMultiplayer.p.w > WIDTH - 1) {
                    PainelMultiplayer.p.x = WIDTH - PainelMultiplayer.p.w - 1;
                }
            ProjetoIntegrado.pmulti.enviaObjeto();
        }

    }
}
